package cn.itcast.bos.service.transit.imp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.transit.InOutStorageInfoDao;
import cn.itcast.bos.dao.transit.TransitInfoDao;
import cn.itcast.bos.domain.transit.InOutStorageInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.transit.InOutStorageInfoService;

@Service
@Transactional
public class InOutStorageInfoServiceImp implements InOutStorageInfoService{
	
	@Autowired
	private InOutStorageInfoDao inOutStorageInfoDao;
	
	@Autowired
	private TransitInfoDao transitInfoDao;
	
	@Override
	public void save(String transitInfoId, InOutStorageInfo inOutStorageInfo) {
		//保存出入库信息
		inOutStorageInfoDao.save(inOutStorageInfo);
		//查询TransitInfo
		TransitInfo info = transitInfoDao.findOne(Integer.parseInt(transitInfoId));
		
		//关联出入库信息到运输配送对象
		info.getInOutStorageInfos().add(inOutStorageInfo);
		
		//修改状态
		if(inOutStorageInfo.getOperation().equals("到达网点")){
			info.setStatus("到达网点");
			//更新网点地址,显示配送路径
			info.setOutletAddress(inOutStorageInfo.getAddress());
		}
		
	}

}
